package com.yinbw.postgresql.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mybatisplus.common.model.param.ParamBean;
import com.mybatisplus.common.page.PageInfo;
import com.mybatisplus.common.page.PageVo;
import org.springframework.beans.factory.annotation.Autowired;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import com.yinbw.postgresql.entity.Zz;
import com.yinbw.postgresql.mapper.ZzMapper;
import com.yinbw.postgresql.service.ZzService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.List;


@Slf4j
@Service
public class ZzServiceImpl extends ServiceImpl<ZzMapper, Zz> implements ZzService {

    @Autowired
    private ZzMapper zzMapper;

    @Override
    public List<Zz> queryList() {
        QueryWrapper<Zz> queryWrapper = new QueryWrapper<>();
        List<Zz> selectList = zzMapper.selectList(queryWrapper);
        return selectList;
    }

    @Override
    public Boolean changeById(Zz zz) {
        int i = zzMapper.updateById(zz);
        return true;
    }

    @Override
    public Boolean removeById(Long id) {
        int i = zzMapper.deleteById(id);
        return true;
    }

    @Override
    public Boolean saveData(Zz zz) {
        int insert = zzMapper.insert(zz);
        return true;
    }

    @Override
    public PageVo page(ParamBean<Zz> paramBean){
        PageVo<Zz> pageVo = new PageVo<>();
        PageInfo pageInfo = new PageInfo();
        Page<Zz> page = new Page<>(paramBean.getPageNum(), paramBean.getPageSize());
        QueryWrapper<Zz> queryWrapper = new QueryWrapper<>();
        zzMapper.selectPage(page,queryWrapper);
        pageVo.setDatas(page.getRecords());
        pageInfo.setTotalPageNum(Integer.valueOf(page.getTotal()+""));
        pageVo.setPageInfo(pageInfo);
        return pageVo;
    }
}
